package xyz.moxj.sp09.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyz.moxj.sp01.pojo.Item;
import xyz.moxj.sp01.pojo.Order;
import xyz.moxj.sp01.pojo.User;
import xyz.moxj.sp01.util.JsonResult;
import xyz.moxj.sp09.feign.ItemClient;
import xyz.moxj.sp09.feign.OrderClient;
import xyz.moxj.sp09.feign.UserClient;

import java.util.List;

@RestController
public class FeignController {
    @Autowired
    private ItemClient itemClient;
    @Autowired
    private UserClient userClient;
    @Autowired
    private OrderClient orderClient;

    @GetMapping("/item-service/{orderId}")
    public JsonResult<List<Item>> getItems(@PathVariable String orderId) {
        return itemClient.getItems(orderId);
    }
    @PostMapping("/item-service/decreaseNumber")
    public JsonResult<?> decreaseNumber(@RequestBody List<Item> items) {
        return itemClient.decreaseNumber(items);
    }
    @GetMapping("/user-service/{userId}")
    public JsonResult<User> getUser(@PathVariable Integer userId) {
        return userClient.getUser(userId);
    }
    @GetMapping("/user-service/{userId}/score")
    public JsonResult<?> addScore(@PathVariable Integer userId,Integer score) {
        return userClient.addScore(userId, score);
    }
    @GetMapping("/order-service/{orderId}")
    public JsonResult<Order> getOrder(@PathVariable String orderId) {
        return orderClient.getOrder(orderId);
    }
    @GetMapping("/order-service/")
    public JsonResult<?> addOrder() {
        return orderClient.addOrder();
    }
}